const BaseIpcHandler = require('../BaseIpcHandler');

class DeleteFramesHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> DeleteFramesHandler params = ', params);
        let { dataset_id, frames } = params;

        // 业务逻辑
        let result = null;
        try {
            let list_db = this.app.list_dbs[dataset_id];
            await list_db.pairs.deletePairs(JSON.parse(frames));
            result = { code: 0, msg: 'Delete Image OK!' };
        } catch (err) {
            console.error(`Delete Image Failed!, Error = `, err);
            result = { code: -1, msg: err.message };
        }

        // 返回结果
        // console.log(`DeleteFramesHandler result = `, result);
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = DeleteFramesHandler;
